/**
 * Copyright &copy; 2012-2016 <a href="https://istep.lczyfz.com">Istep</a> All rights reserved.
 */
package com.lczyfz.istep.modules.resource.web;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import org.apache.shiro.authz.annotation.RequiresPermissions;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.ModelAttribute;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.servlet.mvc.support.RedirectAttributes;

import com.lczyfz.istep.common.config.Global;
import com.lczyfz.istep.common.persistence.Page;
import com.lczyfz.istep.common.web.BaseController;
import com.lczyfz.istep.common.utils.StringUtils;
import com.lczyfz.istep.modules.resource.entity.SceneRouterPort;
import com.lczyfz.istep.modules.resource.service.SceneRouterPortService;

/**
 * 文件上传示例Controller
 * @author dh
 * @version 2017-07-21
 */
@Controller
@RequestMapping(value = "${adminPath}/resource/sceneRouterPort")
public class SceneRouterPortController extends BaseController {

	@Autowired
	private SceneRouterPortService sceneRouterPortService;
	
	@ModelAttribute
	public SceneRouterPort get(@RequestParam(required=false) String id) {
		SceneRouterPort entity = null;
		if (StringUtils.isNotBlank(id)){
			entity = sceneRouterPortService.get(id);
		}
		if (entity == null){
			entity = new SceneRouterPort();
		}
		return entity;
	}
	
	@RequiresPermissions("resource:sceneRouterPort:view")
	@RequestMapping(value = {"list", ""})
	public String list(SceneRouterPort sceneRouterPort, HttpServletRequest request, HttpServletResponse response, Model model) {
		Page<SceneRouterPort> page = sceneRouterPortService.findPage(new Page<SceneRouterPort>(request, response), sceneRouterPort); 
		model.addAttribute("page", page);
		return "modules/resource/sceneRouterPortList";
	}

	@RequiresPermissions("resource:sceneRouterPort:view")
	@RequestMapping(value = "form")
	public String form(SceneRouterPort sceneRouterPort, Model model) {
		model.addAttribute("sceneRouterPort", sceneRouterPort);
		return "modules/resource/sceneRouterPortForm";
	}

	@RequiresPermissions("resource:sceneRouterPort:edit")
	@RequestMapping(value = "save")
	public String save(SceneRouterPort sceneRouterPort, Model model, RedirectAttributes redirectAttributes) {
		if (!beanValidator(model, sceneRouterPort)){
			return form(sceneRouterPort, model);
		}
		sceneRouterPortService.save(sceneRouterPort);
		addMessage(redirectAttributes, "保存文件上传成功");
		return "redirect:"+Global.getAdminPath()+"/resource/sceneRouterPort/?repage";
	}
	
	@RequiresPermissions("resource:sceneRouterPort:edit")
	@RequestMapping(value = "delete")
	public String delete(SceneRouterPort sceneRouterPort, RedirectAttributes redirectAttributes) {
		sceneRouterPortService.delete(sceneRouterPort);
		addMessage(redirectAttributes, "删除文件上传成功");
		return "redirect:"+Global.getAdminPath()+"/resource/sceneRouterPort/?repage";
	}

}